package com.smashcrush.client.gwt;


import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Widget;
import com.smashcrush.client.gwt.client.editor.ScriptsSpace;
import com.smashcrush.model.Script;

public class Workspace extends Composite {

	Grid grid;

	ScriptsSpace scriptsSpace;

	public Workspace() {

		grid = new Grid(2, 1);
		grid.setSize("100%", "100%");

		Header header = new Header(this);
		header.setWidth("100%");
		grid.setWidget(0, 0, header);
		grid.getCellFormatter().setHeight(0, 0, "20%");
		grid.getCellFormatter().setVerticalAlignment(0, 0,
				HasVerticalAlignment.ALIGN_TOP);

		grid.getCellFormatter().setHorizontalAlignment(1, 0,
				HasHorizontalAlignment.ALIGN_CENTER);
		grid.getCellFormatter().setVerticalAlignment(1, 0,
				HasVerticalAlignment.ALIGN_TOP);

		scriptsSpace = new ScriptsSpace();
		setCenter(scriptsSpace);

		initWidget(grid);
	}

	public void showScripts() {
		setCenter(scriptsSpace);
		scriptsSpace.search();
	}

	public void newScript() {
		setCenter(scriptsSpace);
		scriptsSpace.edit(new Script());
	}

	void setCenter(Widget w) {
		grid.setWidget(1, 0, w);
	}

}
